package domain;

import java.util.HashSet;
import java.util.Set;

public class Contact {

	private String firstName;
	private String lastName;
	private String email;
	private Address add;
	private Set<ContactGroup> groups = new HashSet<ContactGroup>();
	private Set<PhoneNumber> phones =  new HashSet<PhoneNumber>();
	private long contactId;
	private int version;

	public Contact(){
	}

	
	public Contact(String firstName, String lastName, String email) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
	}


	public int getVersion() {
		return version;
	}


	public void setVersion(int version ) {
		this.version = version;
	}


	public long getContactId() {
		return contactId;
	}


	public void setContactId(long contactId) {
		this.contactId = contactId;
	}
	
	public Set<ContactGroup> getGroups() {
		return groups;
	}


	public void setGroups(Set<ContactGroup> groups) {
		this.groups = groups;
		
		/*
		for(ContactGroup group : groups) {
			group.getContacts().add(this);
		}*/
	}


	public Set<PhoneNumber> getPhones() {
		return phones;
	}

	public void setPhones(Set<PhoneNumber> phones) {
		this.phones = phones;
		for(PhoneNumber phone : phones) {
			phone.setContact(this);
		}
	}

	public Address getAdd() {
		return add;
	}

	public void setAdd(Address add) {
		this.add = add;
	}

	public String getEmail(){
		return email;
	}

	public void setEmail(String email){
		this.email = email;
	}

	public String getFirstName(){
		return firstName;
	}

	public void setFirstName(String firstname){
		this.firstName = firstname;
	}


	public String getLastName(){
		return lastName;
	}

	public void setLastName(String lastname){
		this.lastName = lastname;
	}

	public void addPhone(PhoneNumber phone) {
		phone.setContact(this);
		if(!phones.contains(phone))
			phones.add(phone);
	}

	public void removePhone(PhoneNumber phone) {
		this.groups.remove(phone);
		phone.setContact(null);
	}
	
	public void addGroup(ContactGroup contactGroup) {
		this.groups.add(contactGroup);
		if (!contactGroup.getContacts().contains(this)) {
			contactGroup.addContact(this);
		}
	}

	public void removeGroup(ContactGroup contactGroup) {
		this.groups.remove(contactGroup);
		if (contactGroup.getContacts().contains(this)) {
			contactGroup.removeContact(this);
		}
	}
}
